package com.fotkidemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import com.fotkidemo.beans.Album;

/**
 * Created with IntelliJ IDEA.
 * User: roma
 * Date: 6/16/12
 * Time: 10:10 PM
 * To change this template use File | Settings | File Templates.
 */

/**
 * Класс отвечает за отображение списка альбомов пользователя на yandex фотках
 */
public class AlbumsShowActivity extends FragmentActivity implements AlbumsFragment.OnAlbumsClickListener {
    private static final String TAG = "AlbumsFragment";
    public static final String EXTRA_URL = "extra_url";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final String url = getIntent().getStringExtra(EXTRA_URL);

        if (url != null) {
            if (getSupportFragmentManager().findFragmentByTag(TAG) == null) {
                final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                ft.add(android.R.id.content, AlbumsFragment.newInstance(url), TAG);
                ft.commit();
            }
        }
    }

    /**
     * Показать фотки удаленного альбома
     */
    @Override
    public void onAlbumClick(int position, Album album, AdapterView<?> adapterView) {
        String[] strs = album.getId().split(":");
        Intent intent = new Intent(this, ImagesShowActivity.class);
        intent.putExtra(ImagesShowActivity.EXTRA_URL, album.getPhotosURL());
        intent.putExtra(ImagesShowActivity.ALBUM_CACHE, strs[strs.length - 1]);
        intent.putExtra(ImagesShowActivity.IMAGE_COUNT, album.getImageCount());
        startActivity(intent);
    }

    @Override
    public void onCreateMenu(Menu menu) {
        menu.close();
    }

    @Override
    public boolean onMenuItemSelected(MenuItem item) {
        return false;
    }
}